/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditPanes.Filter;

import GUI.Components.BTextField;
import GUI.Components.Float3Panel;
import GUI.EditPanes.EditTaskPane;
import General.CurrentData;
import com.jme3.math.Vector3f;
import com.jme3.post.filters.LightScatteringFilter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import se.datadosen.component.RiverLayout;

/**
 *
 * @author David
 */
public class LightScatteringTaskPane extends EditTaskPane
{

    private Float3Panel positionPanel;
    private BTextField blurStartField = new BTextField("Float");
    private BTextField blurWidthField = new BTextField("Float");
    private BTextField densityField = new BTextField("Float");
    private JSlider samplesSlider;

    /**
     *
     * @param scatteringFilter
     */
    public LightScatteringTaskPane(final LightScatteringFilter scatteringFilter)
    {
        positionPanel = new Float3Panel(scatteringFilter.getLightPosition())
        {
            @Override
            public void setVector(Vector3f vec)
            {
                scatteringFilter.setLightPosition(vec);
                super.setVector(vec);
            }
        };
        samplesSlider = new JSlider(1, 600, scatteringFilter.getNbSamples());
        samplesSlider.addChangeListener(new ChangeListener()
        {
            public void stateChanged(ChangeEvent e)
            {
                scatteringFilter.setNbSamples(samplesSlider.getValue());
            }
        });
        blurStartField.setText("" + scatteringFilter.getBlurStart());
        blurWidthField.setText("" + scatteringFilter.getBlurWidth());
        densityField.setText("" + scatteringFilter.getLightDensity());
        taskPane.setLayout(new RiverLayout());
        taskPane.setTitle("Light Scattering Filter");
        add(taskPane, BorderLayout.CENTER);
        applyButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                scatteringFilter.setBlurStart(Float.parseFloat(blurStartField.getText()));
                scatteringFilter.setBlurWidth(Float.parseFloat(blurWidthField.getText()));
                scatteringFilter.setLightDensity(Float.parseFloat(densityField.getText()));
                scatteringFilter.setLightPosition(positionPanel.getVector());
                scatteringFilter.setNbSamples(samplesSlider.getValue());
            }
        });
        taskPane.add("br left", new JLabel("Position:"));
        taskPane.add("tab hfill", positionPanel);
        taskPane.add("br left", new JLabel("Quality:"));
        taskPane.add("tab hfill", samplesSlider);
        taskPane.add("br left", new JLabel("Blur Start:"));
        taskPane.add("tab hfill", blurStartField);
        taskPane.add("br left", new JLabel("Blur Width:"));
        taskPane.add("tab hfill", blurWidthField);
        taskPane.add("br left", new JLabel("Density:"));
        taskPane.add("tab hfill", densityField);
        taskPane.add("br right", applyButton);
    }
}
